#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QRegExp>
#include <QRegExpValidator>
#include <QValidator>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->lineEdit_name->setPlaceholderText("输入用户名");
    ui->lineEdit_name->setClearButtonEnabled(true);

    ui->lineEdit_pwd->setPlaceholderText("输入密码");
    ui->lineEdit_pwd->setClearButtonEnabled(true);
    ui->lineEdit_pwd->setEchoMode(QLineEdit::Password);//设置为密码的形式，这样当输入时就无法查看到了

    ui->lineEdit_tel->setPlaceholderText("输入手机号");
    ui->lineEdit_tel->setClearButtonEnabled(true);
    //限制手机号的格式，"000-0000-0000"
//    ui->lineEdit_tel->setInputMask("000-0000-0000");//实现简单的校验

    //设置验证器
    QRegExp reg("^1\\d{10}$");//^代表开始 以1开头再加上10个整数 &表示结束

    //给lineEdit注册一个验证器
    ui->lineEdit_tel->setValidator(new QRegExpValidator(reg));//注意需要加上 QRegExpValidator的头文件


}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    //获取值并打印查看
    qDebug() << ui->lineEdit_name->text() << " " <<ui->lineEdit_pwd->text()<< " " <<ui->lineEdit_tel->text();
    if(ui->radioButton->isChecked()){
        qDebug() << "男" ;
    }
    else if(ui->radioButton_2->isChecked()){
         qDebug() << "女" ;
    }
}

void Widget::on_lineEdit_tel_textEdited(const QString &arg1)//只要内容发送改变就会触发该信号
{
    QString str = arg1;
    int t;
    //通过输入框调用设置进去的validator进行判断是否符合
    if(ui->lineEdit_tel->validator()->validate(str,t) == QValidator::Acceptable){//符合条件会返回：QValidator::Acceptable
      ui->pushButton->setEnabled(true);
    }
}
